package com.global.college.ui.presenter;

import android.content.Context;

import com.global.college.api.BaseResponseModel;
import com.global.college.api.ProgressSubscriber;
import com.global.college.base.BasePresenter;
import com.global.college.ui.bean.UploadHeaderModel;
import com.global.college.ui.bean.UserDataModel;
import com.global.college.ui.interfaces.IUserInfoView;

/**
 * 用户信息
 */
public class UserInfoPresenter extends BasePresenter {

    private IUserInfoView mIUserInfoView;

    public UserInfoPresenter(Context context) {
        super(context);
    }

    public void setUserInfoViewView(IUserInfoView userInfoViewView){
        mIUserInfoView = userInfoViewView;
    }

    /**
     * 获取用户信息
     * @param
     */
    public void getUserInfo(){
        mAuthRequestClient.getUserInfo().subscribe(new ProgressSubscriber<UserDataModel>(mContext,false) {
            @Override
            public void onNext(UserDataModel baseResponseModel) {
                if(null != mIUserInfoView){
                    mIUserInfoView.onGetUserInfoSuccess(baseResponseModel);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIUserInfoView){
                    mIUserInfoView.onGetUserInfoFail(e.getMessage());
                }
            }
        });
    }

    /**
     * 设置用户信息
     * @param
     */
    public void setUserInfo(String avatar, String nickName, String sex, String userName){
        mAuthRequestClient.setUserInfo( avatar,  nickName,  sex,  userName).subscribe(new ProgressSubscriber<BaseResponseModel>(mContext,true) {
            @Override
            public void onNext(BaseResponseModel smsModel) {
                if(null != mIUserInfoView){
                    mIUserInfoView.onSetUserInfoSuccess(smsModel);
                }
            }
            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIUserInfoView){
                    mIUserInfoView.onSetUserInfoFail(e.getMessage());
                }
            }
        });
    }

    /**
     * 上传头像图片
     * @param
     */
    public void uploadAvatar(String fileName){
        mAuthRequestClient.uploadAvatar(fileName).subscribe(new ProgressSubscriber<UploadHeaderModel>(mContext,true) {
            @Override
            public void onNext(UploadHeaderModel uploadHeaderModel) {
                if(null != mIUserInfoView){
                    mIUserInfoView.onUploadHeaderSuccess(uploadHeaderModel);
                }
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                if(null != mIUserInfoView){
                    mIUserInfoView.onUploadHeaderFail(e.getMessage());
                }
            }
        });
    }
}
